<!DOCTYPE html>
<html>
<head>
    <title>Physics Diagram of Motional EMF</title>
</head>
<body>
    <canvas id="physicsCanvas" width="400" height="350" style="border:1px solid #d3d3d3;"></canvas>
    <script>
        const canvas = document.getElementById('physicsCanvas');
        const ctx = canvas.getContext('2d');

        // Style settings
        ctx.strokeStyle = 'black';
        ctx.fillStyle = 'black';
        ctx.lineWidth = 1.5;

        /**
         * Draws an arrow on the canvas context.
         * @param {CanvasRenderingContext2D} context The canvas context.
         * @param {number} fromx The starting x-coordinate.
         * @param {number} fromy The starting y-coordinate.
         * @param {number} tox The ending x-coordinate.
         * @param {number} toy The ending y-coordinate.
         * @param {number} [headlen=10] The length of the arrowhead.
         */
        function drawArrow(context, fromx, fromy, tox, toy, headlen = 10) {
            const dx = tox - fromx;
            const dy = toy - fromy;
            const angle = Math.atan2(dy, dx);
            context.beginPath();
            context.moveTo(fromx, fromy);
            context.lineTo(tox, toy);
            context.lineTo(tox - headlen * Math.cos(angle - Math.PI / 6), toy - headlen * Math.sin(angle - Math.PI / 6));
            context.moveTo(tox, toy);
            context.lineTo(tox - headlen * Math.cos(angle + Math.PI / 6), toy - headlen * Math.sin(angle + Math.PI / 6));
            context.stroke();
        }

        // 1. Draw the long straight wire
        ctx.beginPath();
        ctx.moveTo(100, 50);
        ctx.lineTo(100, 300);
        ctx.stroke();

        // 2. Draw the current arrow and label 'I'
        // The arrow is on the wire itself, pointing upwards.
        const arrowOnLineY = 160;
        ctx.beginPath();
        ctx.moveTo(100 - 6, arrowOnLineY + 8);
        ctx.lineTo(100, arrowOnLineY);
        ctx.lineTo(100 + 6, arrowOnLineY + 8);
        ctx.stroke();
        
        // Label 'I'
        ctx.font = "italic 22px 'Times New Roman'";
        ctx.textAlign = 'left';
        ctx.fillText('I', 110, 168);

        // 3. Draw the metal rod AB
        const rodY = 200;
        const rodStartX = 140;
        const rodWidth = 180;
        ctx.fillStyle = 'black';
        ctx.fillRect(rodStartX, rodY, rodWidth, 10);

        // 4. Draw the labels 'A' and 'B' for the rod
        ctx.font = "20px 'Times New Roman'";
        ctx.textAlign = 'center';
        ctx.fillText('A', rodStartX, rodY + 30);
        ctx.fillText('B', rodStartX + rodWidth, rodY + 30);

        // 5. Draw the velocity vector 'v'
        const rodCenterX = rodStartX + rodWidth / 2;
        drawArrow(ctx, rodCenterX, rodY, rodCenterX, rodY - 90, 10);

        // Label 'v' for velocity
        ctx.font = "italic 22px 'Times New Roman'";
        ctx.textAlign = 'left';
        ctx.fillText('v', rodCenterX + 8, rodY - 70);

        // 6. Draw the text at the bottom
        ctx.font = '20px "SimSun", serif'; // Use a common Chinese font
        ctx.textAlign = 'center';
        ctx.fillStyle = 'black';
        ctx.fillText('题 10 图', canvas.width / 2, 330);

    </script>
</body>
</html>